package client;

public class FenetreConnexion extends javax.swing.JFrame {

    public FenetreConnexion(Client c) {
        initComponents();
        client = c;
        textFieldPseudo.setText("samir");
        textFieldMotDePasse.setText("samir");
        textFieldNumeroPort.setText("3000");
        textFieldNomServeur.setText("localhost");
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelMotDePasse = new javax.swing.JLabel();
        labelPseudo = new javax.swing.JLabel();
        textFieldPseudo = new javax.swing.JTextField();
        buttonConnexion = new javax.swing.JButton();
        labelMotDePasseOublie = new javax.swing.JLabel();
        textFieldMotDePasse = new javax.swing.JPasswordField();
        labelInscription = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        textFieldNomServeur = new javax.swing.JTextField();
        textFieldNumeroPort = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Fenetre Connexion");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        labelMotDePasse.setText("Mot de passe");

        labelPseudo.setText("Pseudo");

        buttonConnexion.setText("Connexion");
        buttonConnexion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonConnexionActionPerformed(evt);
            }
        });

        labelMotDePasseOublie.setForeground(new java.awt.Color(34, 26, 236));
        labelMotDePasseOublie.setText("Mot de passe oublié ?");

        labelInscription.setForeground(new java.awt.Color(9, 12, 254));
        labelInscription.setText("Créer un compte ?");
        labelInscription.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mouseClickedLabelInscription(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                labelInscriptionMouseEntered(evt);
            }
        });

        jLabel2.setText("Nom serveur");

        jLabel3.setText("Port serveur");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelMotDePasse, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(labelPseudo, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(40, 40, 40)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textFieldMotDePasse, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFieldPseudo, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                    .addComponent(textFieldNumeroPort, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFieldNomServeur))
                .addGap(32, 32, 32))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(111, 111, 111)
                        .addComponent(buttonConnexion, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelInscription)
                            .addComponent(labelMotDePasseOublie))))
                .addContainerGap(94, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(97, 97, 97)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldPseudo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelPseudo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelMotDePasse)
                    .addComponent(textFieldMotDePasse, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(textFieldNomServeur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(textFieldNumeroPort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(28, 28, 28)
                .addComponent(buttonConnexion)
                .addGap(124, 124, 124)
                .addComponent(labelMotDePasseOublie)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(labelInscription)
                .addContainerGap(88, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonConnexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonConnexionActionPerformed
            pseudo = textFieldPseudo.getText();
            motDePasse = textFieldMotDePasse.getSelectedText();
            nomServeur = textFieldNomServeur.getText();
            numeroPort = textFieldNumeroPort.getText();
            if(pseudo.equalsIgnoreCase("")  || nomServeur.equalsIgnoreCase("") ||  numeroPort.equalsIgnoreCase("") ){
                client.afficherMessage("Vous devez remplir tous les champs");
            }else{
                System.out.println("j'appel la méthode connexion");
                client.connexion(pseudo,motDePasse,nomServeur,numeroPort);
            }
    }//GEN-LAST:event_buttonConnexionActionPerformed

    private void mouseClickedLabelInscription(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mouseClickedLabelInscription
        client.afficherFenetreInscription();
    }//GEN-LAST:event_mouseClickedLabelInscription

    private void labelInscriptionMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_labelInscriptionMouseEntered
        
    }//GEN-LAST:event_labelInscriptionMouseEntered

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
       client.fermetureFenetre();
    }//GEN-LAST:event_formWindowClosing

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonConnexion;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel labelInscription;
    private javax.swing.JLabel labelMotDePasse;
    private javax.swing.JLabel labelMotDePasseOublie;
    private javax.swing.JLabel labelPseudo;
    private javax.swing.JPasswordField textFieldMotDePasse;
    private javax.swing.JTextField textFieldNomServeur;
    private javax.swing.JTextField textFieldNumeroPort;
    private javax.swing.JTextField textFieldPseudo;
    // End of variables declaration//GEN-END:variables
    public String pseudo = "";
    public String motDePasse = "";
    public String nomServeur = "";
    public String numeroPort = "";
    public Client client =null;
}
